package com.jyxd.web.util;

import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.data.patient.Patient;
import org.apache.commons.lang.StringUtils;

import java.util.Map;
import java.util.Objects;

import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

public class VitalSignUtil {

    /**
     * 判断该患者是否开启脉搏数据赋值
     *
     * @param patient
     * @return
     */
    public static boolean getIsOpenPulseRecord(Patient patient) {
        if (Objects.isNull(patient)) {
            return false;
        }
        if (Objects.isNull(patient.getIsOpenPulseRecord())) {
            return false;
        }
        if (StringUtils.equals(patient.getIsOpenPulseRecord(), "true")) {
            return true;
        }
        return false;
    }

    /**
     * 判断同步参数是否为空
     *
     * @param requestMap
     */
    public static void queryIsEmpty(Map<String, String> requestMap) {
        errorIfEmpty(requestMap, "必传数据不能为空");
        errorIfEmpty(requestMap.get("time"), "同步时间不能为空");
        errorIfEmpty(requestMap.get("patientId"), "同步患者id不能为空");
    }

    /**
     * 查询患者是否存在
     * @param patient
     * @return
     */
    public static HttpResult isPatientNull(Patient patient){
        if (Objects.isNull(patient)) {
            return new HttpResult(200, "患者数据不存在同步失败");
        }
        if (! Objects.equals(patient.getFlag(), 1) || Objects.equals(patient.getStatus(), - 1)) {
            return new HttpResult(200, "该患者属于出科或删除状态，不进行监护仪数据同步");
        }
        return null;
    }
}
